package cn.cat.main.others;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class CallableClass {

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            FutureTask<Object> futureTask = new FutureTask<Object>(new Callable<Object>() {
                public Object call() throws Exception {
                    int a = 1;
                    int b = 2;
                    System.out.println("a=" + a + ",b=" + b);
                    return a + b;
                }
            });

            //不推荐这种方式执行，想要获取线程结果，需要结合线程池
            Thread thread = new Thread(futureTask);
            thread.start();
        }
    }
}
